package com.dit.action.signIn;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;

import com.dit.action.AbstractAction;
import com.dit.entity.UserLogin;
import com.dit.service.UserService;

public class SignInAction extends AbstractAction {

	@Autowired
	private UserService userService;

	private UserLogin userLogin;

	public String showSignInForm() {

		return SUCCESS;

	}

	public String validateUser() {
		UserLogin validUser = userService.validateUser(userLogin.getUsername(),
				userLogin.getPassword());

		if (validUser == null) {
			return INPUT;
			
		} else {
			
			addSessionUserVariable(validUser);
			
			if(validUser.getUserType().equals("portal_admin")){
				System.out.println("admin");
				return ADMIN;
	
			}
			else if(validUser.getUserType().equals("sme_admin")){
				System.out.println("sme_admin");
				return SME_ADMIN;
	
			}
			else if(validUser.getUserType().equals("employee")){
				System.out.println("employee");
				return EMPLOYEE;
	
			}
			else if(validUser.getUserType().equals("individual_user")){
				System.out.println("user");
				return INDIVIDUAL_USER;
			}
			return ERROR;
		}
	   

	}

	public UserLogin getUserLogin() {
		return userLogin;
	}

	public void setUserLogin(UserLogin userLogin) {
		this.userLogin = userLogin;
	}

}
